# phonetic.awk - v1.01 2010
# authors: Michael S. Sanders, Ed Morton
# license: GPL3
#
# This gawk program file attempts to produce phonetic passwords
# (ie - passwords that are easy to remember) using vowels/consonants.
# Additionally, the 1st letter of the password is capitalized and
# a single digit appended to the result. These two measures will
# satisfy the majority of sites that require alpha/numeric/mixed
# case passwords.
#
# Program usage requires two steps:
#
# - Specify a number between 3 and 9 for the variable: 'password_len'
#
# - Invoke gawk with the name of this file: 'gawk -f phonetic.awk'
#
# Sample output of five iterations: Kana8, Numo3, Jivo5, Rune1, Yubi4

BEGIN {

  srand()

  password_len = 5

  if (password_len < 3 || password_len > 9) {
    print "\nEnter a number 3 to 9...\n"
    exit
  }

  print password(password_len)

}

# ---------------------------------------------------------------------------

function password(num,    vwl, cns, tmp, j) {

   vwl = "aeiou"             # vowels
   cns = "bdfghjklmnprstvwy" # consonants ('nice' only no C, Q, X, Z)

   tmp = toupper(getletter(cns))

   for (j = 2; j < num; j++) {
     tmp = tmp getletter((j % 2 ? cns : vwl))
   }
           
   return tmp rnum(0, 9)
}

# ---------------------------------------------------------------------------

function getletter(arr) {

  return substr(arr, rnum(1, length(arr)), 1)

}

# ---------------------------------------------------------------------------

function rnum(low, hi,    x, y, z) {

  x = rand()
  y = (hi - low) + 1
  z = int((x * y) + low)

  return z
}

# eof
